package com.ywj.collection.javaList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayListTrans {
    public static void main(String[] args) {
        testArray2List();
        System.out.println("~~~~~~~~~~~~~~~~~~");
        testList2Array();
    }

    //数组转List
    public static void testArray2List() {
        String[] strs = {"money", "health", "honor"};
        List<String> list = Arrays.asList(strs);
        for (String s : list) {
            System.out.println(s);
        }
        strs[1] = "study";
        System.out.println("======");
        System.out.println(list);  //[money, study, honor]
    }

    //List转数组
    public static void testList2Array() {
        List<String> list = new ArrayList<>();
        list.add("money");
        list.add("health");
        list.add("honor");
        String[] array = list.toArray(new String[list.size()]);
        for (String s : array) {
            System.out.println(s);
        }
        list.set(1, "study");
        System.out.println("======");
        for (String s : array) {
            System.out.println(s);  // money    health    honor
        }
    }

}
